package api

import (
	"food-mgr/api-getaway/config"
	"food-mgr/api-getaway/handler/request"
	"food-mgr/api-getaway/response"
	__ "food-mgr/food-service/proto"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func CreateOrder(c *gin.Context) {

	var order request.Order
	err := c.ShouldBind(&order)
	if err != nil {
		response.Error(c, "转化失败")
		return
	}

	r, err := config.FoodClient.CreateOrder(c, &__.CreateOrderReq{
		UserId:   int64(order.UserId),
		ShopId:   int64(order.ShopId),
		OrderSn:  order.OrderSn,
		Address:  order.Address,
		Quantity: int64(order.Quantity),
		Money:    float32(order.Money),
		Status:   order.Status,
		BizId:    int64(order.BizId),
		Year:     order.Year,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	c.JSON(http.StatusOK, gin.H{
		"code": r.Code,
		"msg":  r.Msg,
	})
}
